package com.itheima.mall.controller;

import com.itheima.mall.pojo.HomeAdvertise;
import com.itheima.mall.service.SmsHomeAdvertiseService;
import com.itheima.mall.vo.PageResult;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/home/advertise")
public class SmsHomeAdvertiseController {

    @Autowired
    private SmsHomeAdvertiseService smsHomeAdvertiseService;

    /**
     * 分页查询广告
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult> getList(String endTime, String name, Integer pageNum, Integer pageSize, Integer type){
        PageResult pageResult = smsHomeAdvertiseService.getList(endTime,name,pageNum,pageSize,type);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 添加广告
     */
    @PostMapping("/create")
    public ResponseEntity<String> createAdvertise(@RequestBody HomeAdvertise advertise){
        smsHomeAdvertiseService.createAdvertise(advertise);
        return ResponseEntity.ok("ok");
    }

    /**
     * 删除广告
     */
    @PostMapping("/delete")
    public ResponseEntity<String> deleteAdvertise(@RequestParam List<Long> ids){
        smsHomeAdvertiseService.deleteAdvertise(ids);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改上下线状态
     */
    @PostMapping("/update/status/{id}")
    public ResponseEntity<String> updateStatus(@PathVariable Long id,Integer status){
        smsHomeAdvertiseService.updateStatus(id,status);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改广告
     */
    @PostMapping("/update/{id}")
    public ResponseEntity<String> updateAdvertise(@PathVariable Long id,@RequestBody HomeAdvertise advertise){
        smsHomeAdvertiseService.updateAdvertise(id,advertise);
        return ResponseEntity.ok("ok");
    }

    /**
     * 获取广告详情
     */
    @GetMapping("/{id}")
    public ResponseEntity<HomeAdvertise> advertise(@PathVariable Long id){
        HomeAdvertise homeAdvertise = smsHomeAdvertiseService.advertise(id);
        return ResponseEntity.ok(homeAdvertise);
    }

}
